#pragma once
#include <d3d11.h>
#include "Texture2D.h"
#include "IGrahpicsResource.h"

class RenderTarget : public IGraphicsResource
{
	ID3D11RenderTargetView* rt = nullptr;

	ID3D11ShaderResourceView* srv = nullptr;

	unsigned int srv_slot = 0;

	unsigned int width = 0;
	unsigned int height = 0;

public:
	RenderTarget(void);
	~RenderTarget(void);
	RenderTarget(unsigned int width, unsigned int height, DXGI_FORMAT format, ID3D11Device* device = nullptr);
	RenderTarget(ID3D11Texture2D* texture, ID3D11Device* device = nullptr, bool MakeShaderResource = false);

	void ApplyShaderResorce(unsigned int slot);

	ID3D11RenderTargetView* getDXRenderTarget(void) const { return rt; }

	virtual ID3D11ShaderResourceView* getSrv(void) const override;

	unsigned int getWidth(void) { return width; }
	unsigned int getHeight(void) { return height; }

	// copies data in video memory to CPU memory
	virtual void getData(void* data, unsigned int pixelStride);
	// copies resource data in CPU memory to video memory
	virtual void setData(void* data, unsigned int pixelStride);

	// gets the d3d11 object that represents the resource
	virtual ID3D11Resource* getResource(void) const;

	// gets the d3d11 descriptor for this object and copies it onto 'desc'
	virtual void getDesc(void* desc) override { rt->GetDesc((D3D11_RENDER_TARGET_VIEW_DESC*)desc); }
};